home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / portable / clear.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  10.7 KB  |  451 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21.  
  22. /* undefine any macros for functions defined in this module */
  23. #undef    clear
  24. #undef    wclear
  25. #undef    erase
  26. #undef    werase
  27. #undef    clrtobot
  28. #undef    wclrtobot
  29. #undef    clrtoeol
  30. #undef    wclrtoeol
  31.  
  32. /* undefine any macros for functions called by this module if in debug mode */
  33. #ifdef PDCDEBUG
  34. #  undef    clearok
  35. #endif
  36.  
  37. #ifdef PDCDEBUG
  38. char *rcsid_clear  = "$Id$";
  39. #endif
  40.  
  41. /*man-start*********************************************************************
  42.  
  43.   Name:                                                         clear
  44.  
  45.   Synopsis:
  46.       int clear(void);
  47.       int wclear(WINDOW *win);
  48.       int erase(void);
  49.       int werase(WINDOW *win);
  50.       int clrtobot(void);
  51.       int wclrtobot(WINDOW *win);
  52.       int clrtoeol(void);
  53.       int wclrtoeol(WINDOW *win);
  54.  
  55.   X/Open Description:
  56.       The erase() and werase() functions copy blanks to every position
  57.       of the window.
  58.  
  59.       The clear() and wclear() functions are similar to erase() and
  60.       werase() except they also call clearok() to ensure that the
  61.       the screen is cleared on the next call to wrefresh() for that
  62.       window.
  63.  
  64.       The clrtobot() and wclrtobot() functions clear the screen from
  65.       the current cursor position to the end of the current line and
  66.       all remaining lines in the window.
  67.  
  68.       The clrtoeol() and wclrtoeol() functions clear the screen from
  69.       the current cursor position to the end of the current line only.
  70.  
  71.      NOTE: clear(), wclear(), erase(), clrtobot(), and clrtoeol()
  72.      are implemented as macros
  73.  
  74.   PDCurses Description:
  75.  
  76.   X/Open Return Value:
  77.      All functions return OK on success and ERR on error.
  78.  
  79.   X/Open Errors:
  80.      No errors are defined for this function.
  81.  
  82.   NOTE:
  83.      The behaviour of Unix curses is to clear the line with a space
  84.      and attributes of A_NORMAL. PDCurses clears the line with the
  85.      window's current attributes (including current colour). To get
  86.      the behaviour of PDCurses, #define ODCURSES_WCLR in curses.h or
  87.      add -DPDCURSES_WCLR to the compile switches.
  88.  
  89.   Portability                             X/Open    BSD    SYS V
  90.                                           Dec '88
  91.       clear                                 Y        Y       Y
  92.       wclear                                Y        Y       Y
  93.       erase                                 Y        Y       Y
  94.       werase                                Y        Y       Y
  95.       clrtobot                              Y        Y       Y
  96.       wclrtobot                             Y        Y       Y
  97.       clrtoeol                              Y        Y       Y
  98.       wclrtoeol                             Y        Y       Y
  99.  
  100. **man-end**********************************************************************/
  101.  
  102. /***********************************************************************/
  103. int    clear(void)
  104. /***********************************************************************/
  105. {
  106. #ifdef PDCDEBUG
  107.     if (trace_on) PDC_debug("clear() - called\n");
  108. #endif
  109.  
  110.     if  (stdscr == (WINDOW *)NULL)
  111.         return(ERR);
  112.  
  113.     clearok(stdscr, TRUE);
  114.     return(erase());
  115. }
  116. /***********************************************************************/
  117. int    wclear( WINDOW *win )
  118. /***********************************************************************/
  119. {
  120. #ifdef PDCDEBUG
  121.     if (trace_on) PDC_debug("wclear() - called\n");
  122. #endif
  123.  
  124.     if  (win == (WINDOW *)NULL)
  125.         return( ERR );
  126.  
  127.     clearok( win, TRUE );
  128.     return( werase( win ) );
  129. }
  130. /***********************************************************************/
  131. int    erase(void)
  132. /***********************************************************************/
  133. {
  134.     chtype*    end;
  135.     chtype*    start;
  136.     int    y,x;
  137.     chtype    blank;
  138.  
  139. #ifdef PDCDEBUG
  140.     if (trace_on) PDC_debug("erase() - called\n");
  141. #endif
  142.  
  143.     if (stdscr == (WINDOW *)NULL)
  144.         return( ERR );
  145.  
  146. #if defined(PDCURSES_WCLR)
  147.     blank    = stdscr->_blank | stdscr->_attrs;
  148. #else
  149. /* wrs (4/10/93) account for window background */
  150.     blank    = stdscr->_bkgd;
  151. #endif
  152.  
  153.     for (y = stdscr->_tmarg; y <= stdscr->_bmarg; y++)
  154.     {
  155.         start = stdscr->_y[y];
  156.         end = &start[stdscr->_maxx - 1];
  157. /* changed JGB 6/92 < to <= */
  158.         while (start <= end)
  159.         {
  160.             *start++ = blank;
  161.         }
  162.         stdscr->_firstch[y] = 0;
  163.         stdscr->_lastch[y] = stdscr->_maxx - 1;
  164.     }
  165.     stdscr->_cury = stdscr->_tmarg;
  166.     stdscr->_curx = 0;
  167.  
  168.     return( OK );
  169. }
  170. /***********************************************************************/
  171. int    werase(WINDOW *win)
  172. /***********************************************************************/
  173. {
  174.     chtype*    end;
  175.     chtype*    start;
  176.     int    y,x;
  177.     chtype    blank;
  178.  
  179. #ifdef PDCDEBUG
  180.     if (trace_on) PDC_debug("werase() - called\n");
  181. #endif
  182.  
  183.     if (win == (WINDOW *)NULL)
  184.         return( ERR );
  185.  
  186. #if defined(PDCURSES_WCLR)
  187.     blank    = win->_blank | win->_attrs;
  188. #else
  189. /* wrs (4/10/93) account for window background */
  190.     blank    = win->_bkgd;
  191. #endif
  192.  
  193.     for (y = win->_tmarg; y <= win->_bmarg; y++)
  194.     {
  195.         start = win->_y[y];
  196.         end = &start[win->_maxx - 1];
  197. /* changed JGB 6/92 < to <= */
  198.         while (start <= end)
  199.         {
  200.             *start++ = blank;
  201.         }
  202.         win->_firstch[y] = 0;
  203.         win->_lastch[y] = win->_maxx - 1;
  204.     }
  205.     win->_cury = win->_tmarg;
  206.     win->_curx = 0;
  207.  
  208.     return( OK );
  209. }
  210. /***********************************************************************/
  211. int    clrtobot(void)
  212. /***********************************************************************/
  213. {
  214.     int    y;
  215.     int    minx;
  216.     int    startx;
  217.     chtype    blank;
  218.     chtype*    ptr;
  219.     chtype*    end;
  220.     chtype*    maxx;
  221.  
  222. #ifdef PDCDEBUG
  223.     if (trace_on) PDC_debug("clrtobot() - called\n");
  224. #endif
  225.  
  226.     if  (stdscr == (WINDOW *)NULL)
  227.         return( ERR );
  228.  
  229. #if defined(PDCURSES_WCLR)
  230.     blank    = stdscr->_blank | stdscr->_attrs;
  231. #else
  232. /* wrs (4/10/93) account for window background */
  233.     blank    = stdscr->_bkgd;
  234. #endif
  235.  
  236.     startx    = stdscr->_curx;
  237.  
  238.     for (y = stdscr->_cury; y < stdscr->_maxy; y++)
  239.     {
  240.         minx    = _NO_CHANGE;
  241.         end    = &stdscr->_y[y][stdscr->_maxx - 1];
  242.         for (ptr = &stdscr->_y[y][startx]; ptr <= end; ptr++)
  243.         {
  244.             if (*ptr != blank)
  245.             {
  246.                 maxx = ptr;
  247.                 if (minx == _NO_CHANGE)
  248.                 {
  249.                     minx = (int) (ptr - stdscr->_y[y]);
  250.                 }
  251.                 *ptr = blank;
  252.             }
  253.         }
  254.         if (minx != _NO_CHANGE)
  255.         {
  256.             if ((stdscr->_firstch[y] > minx) ||
  257.                 (stdscr->_firstch[y] == _NO_CHANGE))
  258.             {
  259.                 stdscr->_firstch[y] = minx;
  260.                 if (stdscr->_lastch[y] < maxx - stdscr->_y[y])
  261.                 {
  262.                     stdscr->_lastch[y] = (int) (maxx - stdscr->_y[y]);
  263.                 }
  264.             }
  265.         }
  266.         startx = 0;
  267.     }
  268.     return( OK );
  269. }
  270. /***********************************************************************/
  271. int    wclrtobot(WINDOW *win)
  272. /***********************************************************************/
  273. {
  274.     int    y;
  275.     int    minx;
  276.     int    startx;
  277.     chtype    blank;
  278.     chtype*    ptr;
  279.     chtype*    end;
  280.     chtype*    maxx;
  281.  
  282. #ifdef PDCDEBUG
  283.     if (trace_on) PDC_debug("wclrtobot() - called\n");
  284. #endif
  285.  
  286.     if  (win == (WINDOW *)NULL)
  287.         return( ERR );
  288.  
  289. #if defined(PDCURSES_WCLR)
  290.     blank    = win->_blank | win->_attrs;
  291. #else
  292. /* wrs (4/10/93) account for window background */
  293.     blank    = win->_bkgd;
  294. #endif
  295.  
  296.     startx    = win->_curx;
  297.  
  298.     for (y = win->_cury; y < win->_maxy; y++)
  299.     {
  300.         minx    = _NO_CHANGE;
  301.         end    = &win->_y[y][win->_maxx - 1];
  302.         for (ptr = &win->_y[y][startx]; ptr <= end; ptr++)
  303.         {
  304.             if (*ptr != blank)
  305.             {
  306.                 maxx = ptr;
  307.                 if (minx == _NO_CHANGE)
  308.                 {
  309.                     minx = (int) (ptr - win->_y[y]);
  310.                 }
  311.                 *ptr = blank;
  312.             }
  313.         }
  314.         if (minx != _NO_CHANGE)
  315.         {
  316.             if ((win->_firstch[y] > minx) ||
  317.                 (win->_firstch[y] == _NO_CHANGE))
  318.             {
  319.                 win->_firstch[y] = minx;
  320.                 if (win->_lastch[y] < maxx - win->_y[y])
  321.                 {
  322.                     win->_lastch[y] = (int) (maxx - win->_y[y]);
  323.                 }
  324.             }
  325.         }
  326.         startx = 0;
  327.     }
  328.     return( OK );
  329. }
  330. /***********************************************************************/
  331. int    clrtoeol(void)
  332. /***********************************************************************/
  333. {
  334.     int    y;
  335.     int    x;
  336.     int    minx;
  337.     chtype    blank;
  338.     chtype*    maxx;
  339.     chtype*    ptr;
  340.     chtype*    end;
  341.  
  342. #ifdef PDCDEBUG
  343.     if (trace_on) PDC_debug("clrtoeol() - called\n");
  344. #endif
  345.  
  346.     if (stdscr == (WINDOW *)NULL)
  347.         return( ERR );
  348.  
  349.     y    = stdscr->_cury;
  350.     x    = stdscr->_curx;
  351.  
  352. #if defined(PDCURSES_WCLR)
  353.     blank    = stdscr->_blank | stdscr->_attrs;
  354. #else
  355. /* wrs (4/10/93) account for window background */
  356.     blank    = stdscr->_bkgd;
  357. #endif
  358.  
  359.     end    = &stdscr->_y[y][stdscr->_maxx - 1];
  360.     minx    = _NO_CHANGE;
  361.     maxx    = &stdscr->_y[y][x];
  362.  
  363.     for (ptr = maxx; ptr <= end; ptr++)
  364.     {
  365.         if (*ptr != blank)
  366.         {
  367.             maxx = ptr;
  368.             if (minx == _NO_CHANGE)
  369.             {
  370.                 minx = (int) (ptr - stdscr->_y[y]);
  371.             }
  372.             *ptr = blank;
  373.         }
  374.     }
  375.  
  376.     if (minx != _NO_CHANGE)
  377.     {
  378.         if ((stdscr->_firstch[y] > minx) ||
  379.             (stdscr->_firstch[y] == _NO_CHANGE))
  380.         {
  381.             stdscr->_firstch[y] = minx;
  382.         }
  383.         if (stdscr->_lastch[y] < maxx - stdscr->_y[y])
  384.         {
  385.             stdscr->_lastch[y] = (int) (maxx - stdscr->_y[y]);
  386.         }
  387.     }
  388.     return( OK );
  389. }
  390. /***********************************************************************/
  391. int    wclrtoeol(WINDOW *win)
  392. /***********************************************************************/
  393. {
  394.     int    y;
  395.     int    x;
  396.     int    minx;
  397.     chtype    blank;
  398.     chtype*    maxx;
  399.     chtype*    ptr;
  400.     chtype*    end;
  401.  
  402. #ifdef PDCDEBUG
  403.     if (trace_on) PDC_debug("wclrtoeol() - called\n");
  404. #endif
  405.  
  406.     if (win == (WINDOW *)NULL)
  407.         return( ERR );
  408.  
  409.     y    = win->_cury;
  410.     x    = win->_curx;
  411.  
  412. #if defined(PDCURSES_WCLR)
  413.     blank    = win->_blank | win->_attrs;
  414. #else
  415. /* wrs (4/10/93) account for window background */
  416.     blank    = win->_bkgd;
  417. #endif
  418.  
  419.     end    = &win->_y[y][win->_maxx - 1];
  420.     minx    = _NO_CHANGE;
  421.     maxx    = &win->_y[y][x];
  422.  
  423.     for (ptr = maxx; ptr <= end; ptr++)
  424.     {
  425.         if (*ptr != blank)
  426.         {
  427.             maxx = ptr;
  428.             if (minx == _NO_CHANGE)
  429.             {
  430.                 minx = (int) (ptr - win->_y[y]);
  431.             }
  432.             *ptr = blank;
  433.         }
  434.     }
  435.  
  436.     if (minx != _NO_CHANGE)
  437.     {
  438.         if ((win->_firstch[y] > minx) ||
  439.             (win->_firstch[y] == _NO_CHANGE))
  440.         {
  441.             win->_firstch[y] = minx;
  442.         }
  443.         if (win->_lastch[y] < maxx - win->_y[y])
  444.         {
  445.             win->_lastch[y] = (int) (maxx - win->_y[y]);
  446.         }
  447.     }
  448.     return( OK );
  449. }
  450.